﻿using AutoMapper;
using MediatR;
using S.PurchaseAndSales.Infrastructure.Interface.PurchaseForm;
using S.PurchaseAndSales.Read.Api.Application.Command.PurchaseFormCommand;
using S.PurchaseAndSales.Read.Api.Dto;

namespace S.PurchaseAndSales.Read.Api.Application.CommandHandlers.PurchaseFormHandler
{
    /// <summary>
    /// 查看供应商
    /// </summary>
    public class VendorGetByIdCommandHandler : IRequestHandler<VendorGetByIdCommand, GetVendorByIdDto>
    {
        private readonly IVendorRepository repository;
        private readonly IMapper mapper;

        public VendorGetByIdCommandHandler(IVendorRepository repository,IMapper mapper)
        {
            this.repository = repository;
            this.mapper = mapper;
        }
        public async Task<GetVendorByIdDto> Handle(VendorGetByIdCommand request, CancellationToken cancellationToken)
        {
            return mapper.Map<GetVendorByIdDto>(await repository.GetByIdAsync(request.VendorId));
        }
    }
}
